<?php

/*----------------------------------------------+
|  MaxForum					|
|  ===========================================	|
|  By Majd Almontaser				|
|  Released under the License GNU v3.0		|
|  http://www.Max4Dev.com			|
|  ===========================================	|
|  Ttmtt Team - http://www.liioiil.com		|
+-----------------------------------------------*/

if (!defined('MAX_ON')){
	echo "<h1>ACCESS DENIED</h1>You cannot access this file directly.";
	exit();
}

# Get id, making sure it's a number
$cat_id = (int) $_GET['id'];

# Redirect if it's not safe
if ($cat_id == 0) max_redirect('index.php?page=gallery', 'gallery');

/**
* We're safe to go....
**/

# Load star rater
require 'rater/_drawrating.php';

#----------------------------------------
# Pagination stuff
#----------------------------------------

	#----------------------------------------
	# What page are we on?
	#----------------------------------------
	
		$_GET['pg']	= (int) $_GET['pg'];
		$page		= ($_GET['pg'] == 0 || $_GET['pg'] < 1) ? 1 : $_GET['pg'];
		$perpage	= $Gallery->setting('image_perpage');
		
	#----------------------------------------
	# How many images in total?
	# (in this album)
	#----------------------------------------
	
		$query	= mysql_query('SELECT count(id) as images FROM ' . $db_prefix . 'gallery_images WHERE album = ' . $cat_id);
		$row	= mysql_fetch_assoc($query);
		
			$pages = ceil($row['images'] / $perpage);
	
	#----------------------------
	# Calculate page links
	#----------------------------

		$links = '';
		$comma = '';
		
		for ($i = 1; $i <= $pages; ++$i)
		{
			$links .= $space . '<a class="' . (($i == $page) ? 'page-active' : 'page') . '" href="' . $my_address . '?page=gallery&act=view-cat&id=' . $cat_id . '&pg=' . $i . '">' . $i . '</a>';
			
			$space = ' ';
		}

# Starting hooks
$Gallery->template('pages/gallery/view-cat.template.php')->hook('start', 1, 2);

#----------------------------------------
# Get images in this album
#----------------------------------------

$query = mysql_query('
	SELECT
		img.*, m.id as m_id, m.name as m_name
		
	FROM
		' . $db_prefix . 'gallery_images img, ' . $db_prefix . 'members m
	
	WHERE
		img.user = m.id AND
		img.album = ' . $cat_id . '
	
	ORDER BY
		img.title ASC
	
	LIMIT ' . ($page - 1) * $perpage . ', ' . $perpage
);

$totalRows	= mysql_num_rows($query);
$count		= 0;
$rowNum		= 1;

while ($row = mysql_fetch_assoc($query))
{
	$row['title'] = strip_slashes($row['title']);
	
	#------------------------------------
	# Format lang string
	#------------------------------------
	
		$var1 = '<a href="' . max_link('index.php?page=gallery&act=view-image&id=' . $row['id'], 'gallery/view-image/' . $row['id']) . '">' . $row['title'] . '</a>';
		
		$var2 = member_link($row['m_id'], 0);
		
		$image_title = sprintf($lang['image_title'], $var1, $var2);
		
	# Where is the image?
	$image		= '/uploads/gallery/images/t_' . $row['image'];
	$r_image	= '/uploads/gallery/images/r_' . $row['image'];
	
	$Gallery->hook(3);
	++$count;
	$rowNum = ($rowNum == 3) ? 0 : $rowNum + 1;
}

$Gallery->hook(4, 5, 'end');
?>
